*----------------------------------------------------------------------------------------------------------	* 
* RESEARCHERS:		EARN												   									*
* PROGRAMMED BY:	Linea Hasager																			*
* DESCRIPTION:		Robustness tests: Estimations using different bandwidths.						 		*
* CREATED:			Jan. 7, 2019																		   	*
* LAST MODIFIED:	May 27, 2022														       				*
*----------------------------------------------------------------------------------------------------------	*
	

clear 
set more off

// Directories
global in "L:\Workdata\707455\Papers\ABFHP_1999reform\Code\ReStat\Input"
global output "L:\Workdata\707455\Papers\ABFHP_1999reform\Code\ReStat\Output"
global temp "L:\Workdata\707455\Papers\ABFHP_1999reform\Code\ReStat\Temp"


*--------------------------------------------------------------------------------------------------------	

*******************************
* 1) LOAD DATA
*******************************
use "${in}\Analysis_sample.dta", replace



********************************
* 2) ESTIMATIONS AND GRAPHS
********************************


eststo clear
*EARNINGS
local var loenmv_13_y_18 
forval bw = 30(30)360 {
rdrobust `var'_sum day_nr,  kernel(tri) c(0) p(1) h(`bw')
eststo `var'_bw`bw'_e
}
rdrobust `var'_sum day_nr,  kernel(tri) c(0)  p(1)
eststo `var'_e
gen optbw= e(h_r) 
replace optbw=int(optbw)
levelsof optbw, local(optbw)
gen beta= _b[RD_Estimate] 
levelsof beta, local(beta)
coefplot (`var'_bw30_e, aseq(30) \ `var'_bw60_e, aseq(60)  \ `var'_bw90_e, aseq(90) \ `var'_bw120_e, aseq(120) \ `var'_bw150_e, aseq(150) \ `var'_bw180_e, aseq(180) \ `var'_bw210_e, aseq(210) \ `var'_bw240_e, aseq(240) \ `var'_bw270_e, aseq(270) \ `var'_bw300_e, aseq(300) \ `var'_bw330_e, aseq(330) \ `var'_bw360_e, aseq(360) mcolor(black) ciopts(color(black) )) (`var'_e, aseq(`optbw') mcolor(red) ciopts(color(red)) ) , yline(0,  lpattern(dash) lcolor(gs5)) vertical swapnames graphregion(color(white)) xlabel(, angle(vertical)) xtitle("Bandwidth") legend(off) ytitle("Thousand USD") format(%10.0fc)  ylab(-10(5)10)
graph export "${output}\oa_figure5a.png", replace width(5000)
drop optbw beta



eststo clear
*EMPLOYMENT
local var employment_y_18
forval bw = 30(30)360 {
rdrobust `var'_sum day_nr,  kernel(tri) c(0) p(1) h(`bw')
eststo `var'_bw`bw'_e
}
rdrobust `var'_sum day_nr,  kernel(tri) c(0)  p(1)
eststo `var'_e
gen optbw= e(h_r) 
replace optbw=int(optbw)
levelsof optbw, local(optbw)
gen beta= _b[RD_Estimate] 
levelsof beta, local(beta)
coefplot (`var'_bw30_e, aseq(30) \ `var'_bw60_e, aseq(60)  \ `var'_bw90_e, aseq(90) \ `var'_bw120_e, aseq(120) \ `var'_bw150_e, aseq(150) \ `var'_bw180_e, aseq(180) \ `var'_bw210_e, aseq(210) \ `var'_bw240_e, aseq(240) \ `var'_bw270_e, aseq(270) \ `var'_bw300_e, aseq(300) \ `var'_bw330_e, aseq(330) \ `var'_bw360_e, aseq(360) mcolor(black) ciopts(color(black) )) (`var'_e, aseq(`optbw') mcolor(red) ciopts(color(red)) ) , yline(0,  lpattern(dash) lcolor(gs5)) vertical swapnames graphregion(color(white)) xlabel(, angle(vertical)) xtitle("Bandwidth") legend(off) ytitle("Average Annual Rate of Employment") format(%10.1fc) ylab(-0.4(0.2)0.2)
graph export "${output}\oa_figure5b.png", replace width(5000)
drop optbw beta



eststo clear
*COMPLEX JOB
local var complex_job_y18
forval bw = 30(30)360 {
rdrobust `var' day_nr,  kernel(tri) c(0) p(1) h(`bw')
eststo `var'_bw`bw'_e
}
rdrobust `var' day_nr,  kernel(tri) c(0)  p(1)
eststo `var'_e
gen optbw= e(h_r) 
replace optbw=int(optbw)
levelsof optbw, local(optbw)
gen beta= _b[RD_Estimate] 
levelsof beta, local(beta)
coefplot (`var'_bw30_e, aseq(30) \ `var'_bw60_e, aseq(60)  \ `var'_bw90_e, aseq(90) \ `var'_bw120_e, aseq(120) \ `var'_bw150_e, aseq(150) \ `var'_bw180_e, aseq(180) \ `var'_bw210_e, aseq(210) \ `var'_bw240_e, aseq(240) \ `var'_bw270_e, aseq(270) \ `var'_bw300_e, aseq(300) \ `var'_bw330_e, aseq(330) \ `var'_bw360_e, aseq(360) mcolor(black) ciopts(color(black) )) (`var'_e, aseq(`optbw') mcolor(red) ciopts(color(red)) ) , yline(0,  lpattern(dash) lcolor(gs5)) vertical swapnames graphregion(color(white)) xlabel(, angle(vertical)) xtitle("Bandwidth") legend(off) ytitle("Share") format(%10.2fc)
graph export "${output}\oa_figure5c.png", replace width(5000)
drop optbw beta



eststo clear
*NON-COMPLEX JOB
local var non_complex_job_y18
forval bw = 30(30)360 {
rdrobust `var' day_nr,  kernel(tri) c(0) p(1) h(`bw')
eststo `var'_bw`bw'_e
}
rdrobust `var' day_nr,  kernel(tri) c(0)  p(1)
eststo `var'_e
gen optbw= e(h_r) 
replace optbw=int(optbw)
levelsof optbw, local(optbw)
gen beta= _b[RD_Estimate] 
levelsof beta, local(beta)
coefplot (`var'_bw30_e, aseq(30) \ `var'_bw60_e, aseq(60)  \ `var'_bw90_e, aseq(90) \ `var'_bw120_e, aseq(120) \ `var'_bw150_e, aseq(150) \ `var'_bw180_e, aseq(180) \ `var'_bw210_e, aseq(210) \ `var'_bw240_e, aseq(240) \ `var'_bw270_e, aseq(270) \ `var'_bw300_e, aseq(300) \ `var'_bw330_e, aseq(330) \ `var'_bw360_e, aseq(360) mcolor(black) ciopts(color(black) )) (`var'_e, aseq(`optbw') mcolor(red) ciopts(color(red)) ) , yline(0,  lpattern(dash) lcolor(gs5)) vertical swapnames graphregion(color(white)) xlabel(, angle(vertical)) xtitle("Bandwidth") legend(off) ytitle("Share") format(%10.2fc) 
graph export "${output}\oa_figure5d.png", replace width(5000)
drop optbw beta



